<!doctype html>

<html>
<head>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js">
</script>
<?php
include_once('navbar.php');
include_once('superheader.php');
?>

<script>
$(function() {
	
	$( "#subset" ).buttonset();
    $( "#datepicker" ).datepicker();
    $( "#datepicker2" ).datepicker();
    $( "#button5" ).button();
    $( "#button6" ).button();
    $( "#button9" ).button();
    $( "#button10" ).button();
    $("#response").html("");

          var params =  {
          colReq2: "equipment",
        };

        var data = JSON.stringify(params);
         
        $.ajax({
                    cache: false,
                    type: "json",
                    url: "/phpfunctions/lists/listSoftware.php",
                    contentType: "application/json",
                    processData: true,
                    data: data,
                    success: function(res, textStatus, jqXHR){
		      var container = $("#response");
			 var table = $("<table border=\"1\">");
			 var head = $("<tr>");
			 //head.append("<th>MongoId</th>");
			 head.append("<th>Name</th>");
			 head.append("<th>Location</th>");
			 head.append("<th>Barcode</th>");
			 head.append("<th>Type</th>");
			 head.append("<th>Commission Date</th>");
			 head.append("<th>Decomission Date</th>");
		 	 table.append(head);

			 for(var key in res.data.messages)
			 {
				var tr = $("<tr>");
				var message = res.data.messages[key];
				var td = $("<td>");
				/*td.html(message['_id']);
				tr.append(td);*/
					
				var td = $("<td>");
				td.html(message.name);
				tr.append(td);
				
				var td = $("<td>");
				td.html(message.location);
				tr.append(td);
					
				var td = $("<td>");
				td.html(message.barcode);
				tr.append(td);
					
				var td = $("<td>");
				td.html(message.type);
				tr.append(td);
					
				var td = $("<td>");
				td.html(message.comDate);
				tr.append(td);
					
				var td = $("<td>");
				td.html(message.decomDate);
				tr.append(td);
					
				table.append(tr);			
			 }
                         //container.append(JSON.stringify(res['data']));
			container.html(table);
                    },
                    complete: function(XMLHttpRequest, text_status) {

                    }
                  });
    
    
    
    

});
</script>

</head>


<body>
	
		<div id="response" style="position: relative; top:10px; left:400px; height:0px">
      Stuff to be replaced
    </div>
    
	<h2>Add Device:</h2>
	<?php if(isset($_GET["error"])) : ?>
<?php if($_GET["error"] == 'emptyEquip') : ?>
    <div class="ui-widget">
	<p>Please enter all valid equipment information.</p>
	</div>
	<?php endif; ?>
	<?php if($_GET["error"] == 'duplicateEquip') : ?>
    <div class="ui-widget">
	<p>Equipment with that barcode already exists.</p>
	</div>
	<?php endif; ?>
	<?php if($_GET["error"] == 'dateEquip') : ?>
    <div class="ui-widget">
	<p>Ensure decomission date entered is prior to commission date.</p>
	</div>
	<?php endif; ?>
<?php endif; ?>
	<form action="phpfunctions/addequipment.php" method="post">
 	<p>Name: <input type="text" name="name"><br><p>
 	<p>Location: <input type="text" name="location"><p>
 	<p>Barcode: <input type="text" name="barcode"><p>
 	<p>Commission Date: <input type="text" name="comDate" id="datepicker" /></p>
 	<p>Decommission Date: <input type="text" name="decomDate" id="datepicker2" /></p>
 	<input type="radio" name="type" value="desktop">Desktop<br>
 	<input type="radio" name="type" value="laptop">Laptop<br>
 	<input type="radio" name="type" value="newtorkDevice">Network Device<br>
 	<input type="radio" name="type" value="humanInterfaceDevice">Human Interface Device<br>
 	<input type="radio" name="type" value="other">Other<br>
 	<button id="button5" input type="submit" name="submit" value="Submit me!" />Submit</button>
	</form>
	
	<br>
	
	<?php if($_SESSION['role'] != "user") : ?>
		
	<h2>Remove Device:</h2>
	<?php if(isset($_GET["error"])) : ?>
		<?php if($_GET["error"] == 'deleteErrorEquipment') : ?>
    	<div class="ui-widget">
		<p>No equipment with that barcode was found.</p>
		</div>
		<?php endif; ?>
	<?php endif; ?>
	<form action="phpfunctions/deleteequipment.php" method="post">
 	<p>Barcode: <input type="text" name="barcode"><br><p>
 	<button id="button6" input type="submit" name="submit" value="Submit me!" />Submit</button>
	</form>
	
	
	<?php endif; ?>
	
	<br>
	
	<h2>Filter By Type:</h2>
	<form action="devicefiltertype.php" method="post">
 	<p>Type:
 		<select name="type">
	 		  <option  value="desktop">Desktop</option>
   			<option  value="laptop">Laptop</option>
  			 <option  value="newtorkDevice">Network Device   </option>
  			 <option value="humanInterfaceDevice"> Human Interface Device      </option>
   			<option value="other">Other</option>
	 	</select></p>
 		
 		
 		
 	<button id="button9" input type="submit" name="submit" value="Submit me!" />Submit</button>
	</form>
	
	<br>
	<h2>Filter By Location:</h2>
	<form action="devicefilterlocation.php" method="post">
 	<p>Location: <input type="text" name="location"><br><p>
 	<button id="button10" input type="submit" name="submit" value="Submit me!" />Submit</button>
	</form>

	

</body>


</html>